Conversation
Add vmh_log_alloc_stats() which prints only a single-line summary of total allocated/free bytes; call it on every successful allocation in virtual_heap_alloc() instead of the verbose vmh_log_stats(). Both functions are compiled only when CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS is set. This matches the debug capability in place for plain heap allocs. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add a single-line LOG_INF to z_impl_vregion_alloc_align() reporting the lifetime allocator's used and free bytes after each successful allocation. Gated on CONFIG_SYS_HEAP_RUNTIME_STATS. Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Add a debug overlay file to enable alloc heap debugging, with prints of memory usage via logging subsystem. This is added as a separate file as this creates a notable increase in logging traffic and is not something one wants enabled in all builds (e.g. depends on the logging backend bandwidth). Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
kv2019i
requested review from
abonislawski,
dabekjakub,
dbaluta,
iuliana-prodan,
lbetlej,
lgirdwood,
lyakh,
mmaka1 and
plbossart
as code owners
October 2, 2026 15:37
Collaborator
Author
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Invalid vregion states can query uninitialized heap metadata, and the overlay does not reliably enable its INFO-level logs.
Review effort: Balanced
Findings: 3
Open (4)
What changed in this PR
Adds allocation-time diagnostics across SOF heap implementations and a unified debugging overlay.
Changes:
- Logs vregion allocation statistics.
- Adds aggregate virtual-heap usage logging after allocations.
- Provides an overlay enabling runtime heap statistics.
| File | Description |
|---|---|
zephyr/lib/vregion.c |
Logs lifetime and interim heap usage. |
zephyr/lib/regions_mm.c |
Aggregates virtual-heap allocator statistics. |
zephyr/lib/alloc.c |
Logs statistics after virtual-heap allocations. |
zephyr/include/sof/lib/regions_mm.h |
Declares the statistics helper. |
app/debug_heap_allocs.conf |
Enables runtime statistics options. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+8
to
+9
| CONFIG_SYS_HEAP_RUNTIME_STATS=y | ||
| CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS=y |
Comment on lines
+510
to
+514
| #if CONFIG_SYS_HEAP_RUNTIME_STATS | ||
| if (vr->type == VREGION_MEM_TYPE_LIFETIME) { | ||
| LOG_INF("lifetime alloc of %zu, used %zu, free %zu", | ||
| size, vr->lifetime.used, | ||
| vr->lifetime.size - vr->lifetime.used); |
Comment on lines
+515
to
+518
| } else { | ||
| struct sys_memory_stats stats; | ||
|
|
||
| sys_heap_runtime_stats_get(&vr->interim.heap.heap, &stats); |
| heap->logged = true; | ||
| } | ||
|
|
||
| void vmh_log_alloc_stats(struct vmh_heap *heap) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


A series to help debugging heap usage issues. We already have infra to print logs for each alloc, but these were not documented for developers and didn't cover all the heaps (especially not newer "virtual heap" and "vregion").
This series add similar debugging for all major heap implementations (print out usage stats at each alloc), and adds an overlay to enable these all with a single overlay file.